import $util from "@/utils/index.js"
import $api from "@/api/index.js"
import {
	req
} from '@/utils/req.js';
export default {
	state: {
		pageActive: false,
		// status 1待支付，2待服务，3向导接单，4向导出发，5向导到达，6服务中，7服务完成
		activeIndex: 0,
		tabList: [{
			title: '全部',
			id: 0,
			number: 0,
			type: 'total'
		}, {
			title: '待上门',
			id: 3,
			number: 0,
			type: 'door'
		}, {
			title: '待开始',
			id: 5,
			number: 0,
			type: 'wait'
		}, {
			title: '服务中',
			id: 6,
			number: 0,
			type: 'check'
		}, {
			title: '已完成',
			id: 7,
			number: 0,
			type: 'end'
		},
		// {
		// 	title: '退款/售后',
		// 	id: 999
		// },
		{
			title: '已取消',
			id: '-2',
			number: 0,
			type: 'end'
		}],
		param: {
			page: 1,
			status: 0,
		},
		list: {
			data: [],
			last_page: 1,
			current_page: 1
		}
	},
	mutations: {
		updateOrderItem(state, item) {
			let {
				key,
				val
			} = item
			state[key] = val
		}
	},
	actions: {
		async getOrderList({
			commit,
			state
		}, param) {
			let d = await $api.home.orderList(param)
			let oldList = state.list;
			let newList = d;
			let list = {}
			if (param.page == 1) {
				let {
					current_page = 0
				} = newList
				if (!current_page) {
					newList = {
						data: [],
						last_page: 1,
						current_page: 1
					}
				}
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data)
				list = newList;
			}
			commit('updateOrderItem', {
				key: 'list',
				val: list
			})
		},
		// 售后订单
		async getRefundList({
			commit,
			state
		}, param) {
			let d = await $api.order.refundList(param)
			let oldList = state.list;
			let newList = d;
			let list = {}
			if (param.page == 1) {
				let {
					current_page = 0
				} = newList
				if (!current_page) {
					newList = {
						data: [],
						last_page: 1,
						current_page: 1
					}
				}
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data)
				list = newList;
			}
			commit('updateOrderItem', {
				key: 'list',
				val: list
			})
		},
	}
}
